package com.woniuxy.controller.basicscontroller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.woniuxy.pojo.Book;
import com.woniuxy.service.basics.BookService;

@RestController
@RequestMapping("/book")
public class BookController {

	@Autowired
	private BookService bookService;
	
	@RequestMapping("/getAll")
	public PageInfo getAll(Integer pn,String condition) {
		PageInfo pageInfo = bookService.selectAll(pn, condition);
		return pageInfo;
	}
	@RequestMapping("/getMenu")
	public List<String> getMenu() {
		return bookService.selectMenu();
	}
	@RequestMapping("/getMenu2")
	public List<String> getMenu2(String condition) {
		return bookService.selectMenu2(condition);
	}
	@RequestMapping("/getMenuByLevel")
	public List<Book> getMenuByLevel(String bookLevel) {
		return bookService.selectMenuByLevel(bookLevel);
	}
	@RequestMapping("/addBook")
	public String addBook(Book book) {
		bookService.addBook(book);
		return "";
	}
	@RequestMapping("/doUpdate")
	public String doUpdate(Book book) {
		bookService.updateBook(book);
		return "";
	}
	@RequestMapping("/updateBook")
	public Map<String,Object> updateBook(Integer bookId) {
		Book book=bookService.selectByBookId(bookId);
		String name=bookService.selectNameById(book.getBookPid());
		book.setBookPname(name);
		List<Book> menus = bookService.selectMenuByLevel(book.getBookLevel());
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("book", book);
		map.put("menus", menus);
		return map;
	}
}
